package com.neuedu.web;

import com.neuedu.pojo.Userinfo;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 发帖检查是否登录
 */
@WebServlet(name = "GoReCheckServlet",urlPatterns = "/go/recheck")
public class GoReCheckServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // 检查session中是否有login_user
        Userinfo userinfo = (Userinfo)request.getSession().getAttribute("login_user");
        if (userinfo == null){
            // 跳转到登录页
            response.sendRedirect(request.getContextPath()+"/go/login");
        }else {
            // 跳转到发帖页
            // 查询分类信息
            response.sendRedirect(request.getContextPath()+"/go/add");
        }
    }
}
